package cn.yunhe.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.mchange.v2.c3p0.ComboPooledDataSource;
/**
 * 连接池 工具类
 * 
 * @author Administrator
 *
 */
public class C3P0Util {
	private static ComboPooledDataSource pool = new ComboPooledDataSource();

	public static Connection getConnection() {
		try {
			return pool.getConnection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	
	public static void  close(ResultSet rs, Statement st, Connection conn){
		 if(rs != null){
			 try {
				rs.close();//关闭结果集 
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 }
		 if(st != null){
			 try {
				st.close();//关闭Statement对象
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 }
		 if(conn != null){
			 try {
				conn.close();//归还连接, 实质为 将连接 状态 改为 空闲状态 
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 }
	}

}
